
uniform mat4 mWorldViewProj;
uniform mat4 mInvWorld;
uniform mat4 mTransWorld;

uniform vec3 mLensPos;

void main(void)
{
	float lens_r = 3.0;
	float lens_magnify = 1.96;
	float amount = mLensPos.z;

	vec4 lensPos = vec4(mLensPos.xy, 0.0, 0.0);
	vec4 pos = gl_Vertex;
	vec4 lens = pos - lensPos / 2.0;
	float dsq = lens.x * lens.x + lens.y * lens.y;
	float z = sqrt(abs(lens_r * lens_r - lens.x * lens.x - lens.y * lens.y));
	lens = lens * (1.0 - amount) + amount * lens * lens_magnify / z;
	pos = lens + lensPos / 2.0;
	pos = mWorldViewProj * pos;

	gl_Position = pos;
	gl_PointSize = 20.0 / gl_Position.z;

	vec4 normal = vec4(gl_Normal, 0.0);
	normal = mInvWorld * normal;
	normal = normalize(normal);

	gl_FrontColor = gl_BackColor = gl_Color;

	gl_TexCoord[0] = gl_MultiTexCoord0;
}
